package study.supervisorStrategy

import akka.actor.SupervisorStrategy.{Escalate, Restart, Resume, Stop}
import akka.actor.{Actor, ActorRef, ActorSystem, OneForOneStrategy, Props, SupervisorStrategy}
import study.actorOf.Shop
import study.become.TaskManager
import study.msg.Fire

import scala.concurrent.duration.MINUTES

/**
 * @Description: 子actor 奔溃的监督策略
 * @Author: DJJ
 * @Date: 2019/12/12 17:56
 */
class LoanRateQuotes extends Actor {

  override def supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 5, withinTimeRange = (1, MINUTES)) {
    case _:NullPointerException => Restart //重启
    case _:ArithmeticException => Resume
    case _:IllegalArgumentException => Stop
    case _:UnsupportedOperationException => Stop
    case _:Exception => Escalate
  }

  override def receive: Receive = {
    case "hello" =>
      val shop = context.actorOf(Props[LoanRateQuotes1],"LoanRateQuotes1")
      shop ! "hello"
  }
}

object LoanRateQuotes extends App {
  private val shoppingCart = ActorSystem("factory")
  private val task: ActorRef = shoppingCart.actorOf(Props[LoanRateQuotes], "TaskManager")
  task ! "hello"
}

